using Aliphant.Mvvm.XEvent.Interface;
using Aliphant.Mvvm.XEvent.Models;
using Aliphant.Mvvm.XEvent.UI;
using GrpcClient.Managers;
using System.Windows.Input;

namespace GrpcClient.ViewModels
{
    public class LicenseControlViewModel : BindableBase, INavigate
    {
        public LicenseControlViewModel()
        {
            LicenseManager.Instance.PrintRegistryCodeEvent += UpdateRegistryCode;
        }



        private int _role = 0;
        public int Role { get => _role; set => SetProperty(ref _role, value); }

        private int _days = 365;
        public int Days { get => _days; set => SetProperty(ref _days, value); }

        private string _registryCode = string.Empty;
        public string RegistryCode { get => _registryCode; set => SetProperty(ref _registryCode, value); }

        private string _machineCode = string.Empty;
        public string MachineCode { get => _machineCode; set => SetProperty(ref _machineCode, value); }


        public void OnNavigateTo(NavigateParameter navigateParameter)
        {

        }

        public ICommand RegistryCommand
        {
            get => new RelayCommand<object>(async obj =>
            {
                await LicenseManager.Instance.GenerateLicenseKey(MachineCode, Role + 1, Days);
            });
        }


        private void UpdateRegistryCode(string key)
        {
            this.RegistryCode = key;
        }


    }
}
